<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 字符类:[] 表示 有一系列字符可以选择 只要匹配其中任意一个即可
        var rg = /[abc]/;
        console.log(rg.test('agh')); //true
        console.log(rg.test('bgh')); //true
        console.log(rg.test('cgh')); //true
        console.log(rg.test('zgh')); //flase
        console.log('---------------');

        var rg1 = /^[abc]$/ //三选一 只有是 a 或者是 b 或者是c 才是真
        console.log(rg1.test('ac')); //flase
        console.log(rg1.test('ab')); //flase
        console.log(rg1.test('a')); //true
        console.log(rg1.test('az')); //flase
        console.log('---------第二行-----');

        var rg2 = /^[a-z]$/; //只有a-z 其中一个 才是真
        console.log(rg2.test('z')); //true
        console.log(rg2.test('ab')); //false
        console.log(rg2.test('A')); //false
        console.log('---------第三行-----');

        var rg3 = /[a-z]/; //输入任意只有是a-z的字符
        console.log(rg3.test('xadasfsdfs')); //true
        console.log('---------第四行-----');

        var rg4 = /^[a-zA-Z0-9_]$/ //三选一 只有是a-z A-Z 0-9    _ 才是真
        console.log(rg4.test('A')); //true
        console.log(rg4.test('7')); //true
        console.log(rg4.test('10')); //false
        console.log(rg4.test('9')); //true
        console.log('---------第五行-----');

        var rg5 = /^[^a-zA-Z0-9_]$/ // [^]取反操作 
        console.log(rg5.test('A')); //false
        console.log(rg5.test('7')); //false
        console.log(rg5.test('!')); //true
        console.log(rg5.test('a')); //false
    </script>
</body>

</html>